
    <link href="/public/static/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/public/static/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="/public/static/plugin/AdminLTE/css/AdminLTE.css" rel="stylesheet" type="text/css" />
    <link href="/public/static/plugin/AdminLTE/css/AdminLTE-singular.css" rel="stylesheet" type="text/css" />

    <!-- 基础自定义css -->
    <link href="/public/static/css/normal.css" rel="stylesheet" type="text/css" />
    <link href="/public/static/plugin/jqueryui/jquery.ui.css" rel="stylesheet" type="text/css" />
    <!-- chosen.js -->
    <link href="/public/static/plugin/chosen/chosen.css" rel="stylesheet" type="text/css" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="/public/static/js/html5shiv.js"></script>
    <script src="/public/static/js/respond.min.js"></script>
    <![endif]-->

    <!-- add new calendar event modal -->

    <!-- Start  基础脚本1 -->
    <script src="/public/static/js/jquery.min.js"></script>
    <script src="/public/static/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/public/static/plugin/jqueryui/jquery.ui.js" type="text/javascript"></script>
    <!-- End    基础脚本1 -->	
    <script src="/public/static/plugin/layer/layer.js"></script>
    <script src="/public/static/plugin/chosen/chosen.jquery.js" type="text/javascript"></script>
<style>
	table{
		font-size: 12px;
	}
	.description { color: #999; font-size: 13px; }
    .send-item-list li, .send-pet-list li { margin: 8px 0; }
    .send-item-list li .form-control, .send-pet-list li .form-control { margin-right: 2px; }
    .tools-btn { padding: 5px 7px; border-radius: 12px; }
    .div_item_name{float: left;}
    .div_item_id{float: left;}
    .t_text{float: left; width: 7%;}
    .t_info{float: left;width: 90%;}
    .t_desc{float: left;width: 90%;}
    .t_item{float: left;width: 90%;}
</style>


    <{include file='../common_params.tpl'}>
    <div class="box box-black">
        <div class="box-body">
        	<input type="hidden" value="<{$id}>" id="message_id" name="message_id"/>
        	<h5> <i class="fa fa-users"></i>&nbsp;&nbsp;信息</h5>
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 10%;"></col>
                    <col style="width: 90%;"></col>
                </colgroup>
                
                <tr>
                    <th class="th-label">使用模板</th>
                    <td>
                    	<div style="padding-top: 5px;">
                    		<input type="radio" name="is_use_templet" id="is_use_templet1" value="1" checked="checked"/>是
                    		&nbsp;&nbsp;
                    	    <input type="radio" name="is_use_templet" id="is_use_templet2" value="2" />否
                    	</div>	
                    </td>
                </tr>
                
                <tr class="reply_templet">
                    <th class="th-label">回复模板</th>
                    <td>
                    	<select id="templet" class="form-control inline" name="templet">
                    		<option value="">请选择</option>
                    		<{foreach from=$replyTemplateList item=item key=key}>
                    			<option value="<{$key}>"><{$item}></option>
                    		<{/foreach}>
                    	</select>
                    </td>
                </tr>
                
                <tr class="templet_info" style="display: none;">
                    <th class="th-label">模板信息</th>
                    <td>
                    	<div class="t_text">标题：</div><div class="t_info" style="color: #428bca;"></div>
                    	<div class="t_text">内容：</div><div class="t_desc" style="color: #428bca;"></div>
                    	<div class="t_text">物品：</div><div class="t_item" style="color: #428bca;"></div>
                    </td>
                </tr>
                
                
                <tr class="no_reply_templet" style="display: none;">
                    <th class="th-label">回复标题</th>
                    <td><input type="text" class="form-control inline" name="title" /></td>
                </tr>

                <tr class="no_reply_templet" style="display: none;">
                    <th class="th-label">回复内容</th>
                    <td><textarea class="form-control" name="content" rows="5"></textarea></td>
                </tr>
    
                <tr class="no_reply_templet" style="display: none;">
                    <th class="th-label">发送道具</th>
                    <td>
                    	<div style="padding-top: 5px;">
                    		<input type="radio" name="is_send_good" id="is_send_good1" value="1" checked="checked" />是
                    		&nbsp;&nbsp;
                    	    <input type="radio" name="is_send_good" id="is_send_good2" value="2" />否
                    	</div>	
                    </td>
                </tr>
                
                <{include file="tpl/send_item.tpl"}>
                
            </table>
            
           
  
        </div>

        <div class="box-footer">
            <button type="button" name="sub" class="btn btn-default pull-right"><i class="fa fa-paper-plane-o"></i> 确定</button>
            <div style="clear: both;"></div>
        </div>
    </div>

<script>
$(function(){
	$('.attach-info').hide();
	$('input[name="item_description[]"]').hide();
	
	$("#is_use_templet1").live('click',function(){
		$('.reply_templet').show();
		$('.no_reply_templet').hide();
		$('.attach-info').hide();
		var templet = $('select[name = "templet"]').val();
		if(templet != ''){
			$(".templet_info").show();
		}
		
	});
	
	$("#is_use_templet2").live('click',function(){
		$('.no_reply_templet').show();
		$('.reply_templet').hide();
		$(".templet_info").hide();
		var is_send_good = $("input[name='is_send_good']:checked").val();
		if(is_send_good == 1){
			$('.attach-info').show();
		}
	});
	
	$("#is_send_good1").live('click',function(){
		$('.attach-info').show();
	});
	
	$("#is_send_good2").live('click',function(){
		$('.attach-info').hide();
	});
	
	$(".tools-btn-add").live('click',function(){
		$('input[name="item_description[]"]').hide();
	});
	
	
	$(document).on('change','select[name = "templet"]',function(){
        	var g = $('input[name="g"]').val();
	        var url = '?r=replyTemplate/getInfo&g='+g;
        	
        	var id = $(this).val();
        	if(id == ''){
				$(".templet_info").hide();
				$(".t_info").html('');
				$(".t_desc").html('');
				$(".t_item").html('');
				return false;
			}
        	
          	$.ajax({
	        	type : 'POST',
	        	url : url,
	        	async:false,
	        	data : {'id':id},
		        dataType :'JSON',
		        success : function(res){
		        	if(res.status){	
		        		$(".templet_info").show();
				        $(".t_info").html(res.data.title);
				        $(".t_desc").html(res.data.content);
				        $(".t_item").html(res.data.item);
					   //layer.alert('设置成功', {icon: 1, skin: 'layui-layer-molv'});
			        }else{
			        	$(".t_info").html('<font color="red">'+res.msg+'</font>');
				        $(".t_desc").html('<font color="red">'+res.msg+'</font>');
				        $(".t_item").html('<font color="red">'+res.msg+'</font>');
			        	layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
			        	
			        }
		        }
	        });
    });
    
    
    //回复并保持记录
    var nameflag = true;
    var idflag = true;
    var numberflag = true;
    $('button[name="sub"]').click(function(){ 
        var is_use_templet = $('input[name="is_use_templet"]:checked').val();
        var is_send_good = $('input[name="is_send_good"]:checked').val();
        	
        if(is_use_templet == 1){  //使用模板
        	var templet = $('select[name = "templet"]').val();
		    if(templet == ''){
		        layer.alert('请选择回复模板', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
		    }
        		
        }else{ // == 2 使用模板
        		
        	var title = $('input[name="title"]').val();
        	if(title == ''){
        		layer.alert('请填写邮件标题', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var content = $('textarea[name="content"]').val();
        	if(content == ''){
        		layer.alert('请填写邮件内容', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var content_l = content.length;
        	if(content_l > 1000){
        		layer.alert('邮件内容不能超过1000字', {icon: 2, skin: 'layui-layer-molv'});
        		return false;
        	}
        	
        	var item_name_s = '';
        	$('input[name="item_name[]"]').each(function (i){
        		if($(this).val() == ''){
        			nameflag = false;
        		}else{
        			nameflag = true;
        		}
        		item_name_s += $(this).val() + ',';
            });
            item_name_s = item_name_s.substr(0, item_name_s.length - 1);  
            
            if(!nameflag && is_send_good == 1){
            	layer.alert('请填写道具名称', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }

            var item_id_s = '';
            $('input[name="item_id[]"]').each(function (i){
        		if($(this).val() == ''){
        			idflag =  false;
        		}else{
        			idflag = true;
        		}
        		item_id_s += $(this).val() + ',';
            });
            item_id_s = item_id_s.substr(0, item_id_s.length - 1);  
            
            if(!idflag && is_send_good == 1){
            	layer.alert('请填写道具ID', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
            
            var item_number_s = '';
            $('input[name="item_number[]"]').each(function (i){
            	var max_overlap = $(this).attr('data-max');
            	_sthis = $(this);
		        var num = $(this).val();
        		if($(this).val() == ''){
        			numberflag = false;
        		}else if(parseInt(num) > parseInt(max_overlap)){
        			_sthis.val(max_overlap);
        		}else{
        			numberflag = true;
        		}
        		item_number_s += $(this).val() + ',';
            });
            item_number_s = item_number_s.substr(0, item_number_s.length - 1); 
            
            if(!numberflag && is_send_good == 1){
            	layer.alert('请填写道具数量', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
            
            var is_bind_s = '';
            $('select[name="is_bind[]"]').each(function (i){
        		is_bind_s += $(this).val() + ',';
            });
            is_bind_s = is_bind_s.substr(0, is_bind_s.length - 1); 
        }
        
        var message_id = $("#message_id").val();
        console.log(message_id);
        var g = $('input[name="g"]').val();
	    var url = '?r=message/reply&g='+g;
        $.ajax({
    		type : 'POST',
    		url : url,
			data : {'message_id':message_id,'is_use_templet':is_use_templet,'is_send_good':is_send_good,'title':title,'content':content,'item_name':item_name_s,'item_id':item_id_s,'item_number':item_number_s,'is_bind':is_bind_s,'templet':templet},
			dataType :'JSON',
			success : function(res){
				layer.closeAll();
				if(res.status == 1){						
					window.parent.call_back(res.msg);
				}else{
					layer.alert(res.msg, {icon: 2,time: 2000});
				}
			}
		});
        
    });
    
    
});	
</script>
